<?php

namespace App;
use Session;
use Illuminate\Database\Eloquent\Model;
use DB;
class Brand extends Model{
    //品牌展示  分页
    public function lists($brand_name=''){
       return $info= DB::table('brand')->where('brand_name','like','%'.$brand_name.'%')->paginate(5);

    }
    //查询所有品牌
    public function getBrand($brand_name=''){
       return $info= DB::table('brand')->get();
    }

    //添加品牌
    public function add($data){
      $info = [
        'brand_name'=>$data['brand_name'],
        'brand_url'=>$data['brand_url'],
        'brand_logo'=>$data['path'],
        'brand_sort'=>$data['brand_sort'],
        'brand_info'=>$data['brand_info'],
        'is_show'=>$data['is_show']
      ];
       return DB::table('brand')->insert($info);

    }

    //删除品牌 修改状态值
    public function del($brand_id){
        return DB::table('brand')->where('brand_id',$brand_id)->update(['status'=>1,'is_show'=>0]);

    }

    //品牌 修改状态值
    public function back($brand_id){
        return DB::table('brand')->where('brand_id',$brand_id)->update(['status'=>0,'is_show'=>1]);

    }

    //修改品牌
    public function edit($data){
        $info = [
          'brand_name'=>$data['brand_name'],
          'brand_url'=>$data['brand_url'],
          'brand_logo'=>$data['path'],
          'brand_sort'=>$data['brand_sort'],
          'brand_info'=>$data['brand_info'],
          'is_show'=>$data['is_show']
        ];
        return DB::table('brand')->where('brand_id',$_POST['brand_id'])->update($info);
    }  	

    public function findOne($brand_id){
            $listOne = DB::table('brand')->where('brand_id',$brand_id)->first();
            return $listOne;

    }
}
